<?php
class C_config extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_config');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			default :
                $data = $this->m_config->_data();
				$this->load->view('app/v_config',$data);
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['config_dashboard'] = nosql_post("config_dashboard");
		$data['config_refresh'] = nosql_post("config_refresh");
		echo $this->m_config->_list($data);
	}
	
	function _insert(){
		$data = array(
			'config_dashboard' => $this->input->post('config_dashboard'), 
			'config_refresh'   => $this->input->post('config_refresh'),
			'config_suara'   => $this->input->post('config_suara'), 
			  
			'config_active'    => '1',
			'config_insert_user' =>$_SESSION[SESSION_USERID],
			'config_insert_date' => date("Y-m-d h:i:s"));
		$this->m_config->_insert($data);
		echo 1;
	}
	
	function _update(){
		$config_id = $this->input->post('config_id');
		$data = array(
			'config_dashboard' => $this->input->post('config_dashboard'), 
			'config_refresh' => $this->input->post('config_refresh'), 
			'config_suara'   => $this->input->post('config_suara'), 
			
			'config_update_user'	=> $_SESSION[SESSION_USERID],
			'config_update_date'=> date("Y-m-d h:i:s"));
		$this->m_config->_update($data,$config_id);
		echo 1;
 	}
	
	function _delete(){
		$config_id= $this->input->post('config_id');
		$data = array(
			'config_active' => '0'
		);
		$this->m_config->_delete($data,$config_id);
		echo 1;
	}
}